package sigec_ead.controle.usuario;

import java.sql.*;
import java.util.*;
import sigec_ead.controle.ConexaoJDBC;
import sigec_ead.modelo.usuario.Funcao;

/**
 *
 * @author Joeldson
 */
public class FuncaoDAO {
    private List<String> result;

    public Funcao consultarFuncao(String nome) throws SQLException {

        PreparedStatement ps = null;
        Connection con = null;

        String sql = "SELECT * FROM funcao WHERE nome = ?";

        try {
            con = ConexaoJDBC.getConexao();
            ps = con.prepareStatement(sql);
            ps.setString(1, nome);
            ResultSet rs = ps.executeQuery();
            Funcao f = new Funcao();
            if (rs.next()) {
                f.setId(rs.getInt("id"));
                f.setNome(rs.getString("nome"));
                return f;
            } else {
                return null;
            }
        } finally {
            ps.close();
            con.close();
        }
    }

      public List<String> funcoes() throws SQLException {

        PreparedStatement ps = null;
        Connection con = null;

        String sql = "SELECT * FROM funcao where id!=0";

        try {
            con = ConexaoJDBC.getConexao();
            ps = con.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();

            result = new ArrayList<String>();
            result.add("");
            while (rs.next()) {
                result.add(rs.getString("nome"));
            }
        } finally {
            ps.close();
            con.close();
        }
        return result;
    }
}
